﻿using NodeCanvas.Framework;
using UnityEngine;

namespace Yoozoo.Gameplay.City.AI.Node
{
    public class AIBaseNode: ActionTask
    {
        protected CityAIEntity _entity;
        
        protected Transform _transform;
        protected Animator _animator;
        protected Animator _moveAnimator;
        
        protected override string OnInit()
        {
            _entity = ownerSystemBlackboard.GetVariable<CityAIEntity>("CityAIEntity").value;
            _transform = _entity.viewer.transform;
            _animator = _entity.viewer.animator;
            _moveAnimator = _entity.viewer.moveAnimator;
            return null;
        }
        
        protected virtual void SetPosition(Vector3 pos)
        {
            _transform.position = pos;
           
            //_entity.data.position = pos;
        }

        protected virtual void SetRotation(Vector3 rot)
        {
            _transform.eulerAngles = rot;
       
           //_entity.data.rotation = rot;
        }

        protected virtual void PlayAnimation(string state)
        {
            foreach (var param in _animator.parameters)
            {
                _animator.ResetTrigger(param.name);
            }
            _animator.SetTrigger(state);
        }

        protected virtual void PlayMoveAnimation(string state)
        {
            foreach (var param in _animator.parameters)
            {
                _moveAnimator.ResetTrigger(param.name);
            }
            _moveAnimator.SetTrigger(state);
        }

    }
}